package com.wz.utils;


import java.util.Map;

/**
 * <p>Project: wz_api - MapUtil
 * <p>Powered by pisces On 2022-01-13 22:16:21
 * <P>Created by IntelliJ IDEA
 *
 * @author ww606851@163.com
 * @version 1.0
 * @description:
 * @since 8
 */

public class MapUtil {
    /**
     * 获取map中对应key的值
     *
     * @param
     * @return 如果map或key为空  或者不包含key返回空字符串 否则返回该key的值
     **/

    public static String getValue(Map map, String key) {
        if (null == key || null == map)
            return "";
        // 判断map中是否含有key
        if (!map.containsKey(key))
            return "";
        Object obj = map.get(key);
        if (null == obj) return "";
        return map.get(key).toString();
    }

    public static double getDoubleValue(Map map, String key) {
        if (key == null || map == null) {
            return 0d;
        }
        if (!map.containsKey(key)) return 0d;
        Object obj = map.get(key);
        if (obj == null) return 0d;
        return Double.parseDouble(obj.toString());
    }

    public static int getIntValue(Map map, String key) {
        if (key == null || map == null) return -1;
        if (!map.containsKey(key)) return -1;
        Object obj = map.get(key);
        if (obj == null) return -1;
        return Integer.parseInt(obj.toString());
    }
}
